<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%--根据物品名称获取总价--%>
<%
    JSONObject jsonData = new JSONObject();
    RecordSet rs = new RecordSet();
    String requestid = Util.null2String(request.getParameter("requestid"));
    rs.executeQuery("select id from formtable_main_286 where requestid=?", requestid);
    rs.next();
    rs.next();
    String mainid = Util.null2String(rs.getString("id"));
    rs.executeQuery("select sum(df) from view_custom_ksdf where mainid="+mainid);
    rs.next();
    String df = Util.null2String(rs.getString(1));
    boolean flag = rs.executeUpdate("update formtable_main_286 set sjdf='"+df+"' where id="+mainid);
    if(flag){
        updateKstzmx(requestid);
    }
    jsonData.put( "flag", flag );
    out.print( jsonData.toJSONString() );
%>
<%!
    public static void updateKstzmx(String requestid){
        RecordSet rs = new RecordSet();
        String sql ="select dtr,jmsjid,kslx,dtsc,jjsj,sjdf,sjsplc from formtable_main_286 where requestid=?";
        rs.executeQuery(sql, requestid);
        rs.next();
        String dtr = Util.null2String(rs.getString("dtr"));
        int dtsc = Util.getIntValue(rs.getString("dtsc"),0);
        String jjsj = Util.null2String(rs.getString("jjsj"));
        double sjdf = Util.getDoubleValue(rs.getString("sjdf"),0);
        String sjsplc = Util.null2String(rs.getString("sjsplc"));
        String jmsjid  = getIdToRequestid(sjsplc,"uf_kstjtz");
        String update_sql  ="update uf_kstjtz_dt1 set sjtjsj='"+jjsj+"',dtscfz='"+dtsc+"',sjdf='"+sjdf+"'," +
                "sjxq='"+requestid+"' where mainid=? and dtr=?";
        rs.executeUpdate(update_sql,jmsjid,dtr);
    }

    public static String getIdToRequestid(String requestid,String tablename){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select id from "+tablename+" where lcck=?",requestid);
        rs.next();
        return Util.null2String(rs.getString(1));
    }
%>





